import { _decorator, Component, Node, Label } from "cc";
const { ccclass, property } = _decorator;
import { CheckOutEnum } from "db://assets/Scripts/Utils/CheckOutEnum";
import { CommonUtil } from "db://assets/Scripts/Utils/CommonUtil";

@ccclass("BeginInterfaceManager")
export class BeginInterfaceManager extends Component {
  enumsData: any;
  commonUtil: CommonUtil;
  checkOutEnum: CheckOutEnum;

  titleLabelName: string = "TitleLabel";
  beginNodeName: string = "BeginInterface";

  @property
  localBeginNode: Node = null;

  constructor() {
    super();
    this.checkOutEnum = CheckOutEnum.getInstance();
    this.enumsData = this.checkOutEnum.getEnumByType();
    this.commonUtil = CommonUtil.getInstance();
  }

  setTitleLabel() {
    const titleLabel = this.localBeginNode.getChildByName(this.titleLabelName);
    const titleLabelComp = titleLabel.getComponent(Label);
    titleLabelComp.string = this.enumsData.GAME_NAME;
  }

  buttonConfig(labelSentence: string = "", buttonName: string) {
    const buttonNode = this.localBeginNode.getChildByName(buttonName);
    const buttonNodeLabel = buttonNode.getChildByName("Label");
    const buttonNodeLabelComp = buttonNodeLabel.getComponent(Label);
    buttonNodeLabelComp.string = labelSentence;
  }

  initBeginInterface() {
    this.localBeginNode = this.node.getChildByName(this.beginNodeName);
    this.setTitleLabel();
    this.buttonConfig(this.enumsData.START_NEW_GAME, "StartNew");
    this.buttonConfig(this.enumsData.LOAD_PAST, "LoadPast");
    this.buttonConfig(this.enumsData.SETTING, "Setting");
  }
}
